package logic

import (
	"camera/B/Rpc/model/mysql"
	"context"
	"fmt"

	"camera/B/Rpc/camera"
	"camera/B/Rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodListLogic {
	return &GoodListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodListLogic) GoodList(in *camera.GoodListRequest) (*camera.GoodListResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Good{}
	user, err := g.GetGoods(int(in.Status), int(in.Page), int(in.Status))
	if err != nil {
		return nil, fmt.Errorf("查询失败")
	}
	var goodId []*camera.GoodList
	for _, u := range user {
		goodId = append(goodId, &camera.GoodList{
			GoodTitle: u.GoodTitle,
			GoodStock: int64(u.GoodStock),
			GoodImage: u.GoodImage,
			GoodPrice: float32(u.GoodPrice),
			GoodLike:  int64(u.GoodLike),
			Status:    int64(u.Status),
			Id:        int64(u.ID),
		})
	}
	return &camera.GoodListResponse{
		Goodlist: goodId,
	}, nil
}
